<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-menu"></i> 用户管理</el-breadcrumb-item>
                <el-breadcrumb-item>首页</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="handle-box">
            <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button>
            <el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10"></el-input>
            <el-button type="primary" icon="search" @click="search">搜索</el-button>
        </div>
        <el-table :data="data" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange" v-loading="loading">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="id" label="ID" sortable width="150">
            </el-table-column>
            <el-table-column prop="email" label="邮箱地址" width="350">
            </el-table-column>
            <el-table-column prop="name" label="用户名" >
            </el-table-column>
            <el-table-column label="操作" width="180">
                <template scope="scope">
                    <el-button size="small"
                        @click="handleshenhe(scope.$index)">审核</el-button>
                    <i class="el-icon-delete" @click="handleDelete(scope.row.id)" title="删除"></i>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination
                    @current-change ="handleCurrentChange"
                    layout="prev, pager, next"
                    :total="count"
                    :page-size="showpage">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                url: './static/vuetable.json',
                tableData: [],
                cur_page: 1,
                multipleSelection: [],
                select_word: '',
                del_list: [],
                is_search: false,
                showpage:15,
                token:'',
                total:0,
                loading:true
            }
        },
        created(){
        	this.token=this.$cookie.get('token');
            this.getData();
        },
        computed: {
            data(){
                const self = this;
                return self.tableData;
            },
            count(){
            	return parseInt(this.total);
            }
        },
        watch:{
     
        },
        methods: {
            handleCurrentChange(val){
                this.cur_page = val;
                this.getData();
            },
            getData(){
                let self = this;
                //self.tableData = res.data.list;
		      this.$http({
		          method:'GET',
		          url:'http://www.yuyue.com/api/user?page='+self.cur_page+'&showpage='+self.showpage
		      }).then(function(info){
		      		var data=info.data;
		      		if(data.code == 200){
		      			self.tableData=data.data.data;
		      			self.total=data.data.total;
		      			self.loading=false;
		      		}
		      },function(error){
		          if(error.code == 500){
		          	this.throw_notice('服务器错误!');
		          }else{
		          	this.throw_notice('数据异常!');
		          }
		      })
            },
            search(){
                this.is_search = true;
            },
            filterTag(value, row) {
                return row.tag === value;
            },
            handleDelete(index) {
                let self = this;
                //self.tableData = res.data.list;
		      this.$http({
		          method:'delete',
		          url:'http://www.yuyue.com/api/user/'+index
		      }).then(function(info){
		      		var data=info.data;
		      		if(data.code == 200){
		      			this.throw_notice('删除成功');
		      			this.getData();
		      		}else{
		      			this.throw_notice(data.msg);
		      		}
		      },function(error){
		          if(error.code == 500){
		          	this.throw_notice('服务器错误!');
		          }else{
		          	this.throw_notice('数据异常!');
		          }
		      })
            },
            delAll(){
                const self = this,
                    length = self.multipleSelection.length;
                let str = '';
                self.del_list = self.del_list.concat(self.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += self.multipleSelection[i].name + ' ';
                }
                self.$message.error('删除了'+str);
                self.multipleSelection = [];
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style scoped>
.handle-box{
    margin-bottom: 20px;
}
.handle-select{
    width: 120px;
}
.handle-input{
    width: 300px;
    display: inline-block;
}
</style>